package com.jf3q.sup.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jf3q.sup.domain.Suppliers;
import com.jf3q.sup.dto.SupplierPageDto;
import com.jf3q.sup.service.SuppliersService;
import com.jf3q.sup.mapper.SuppliersMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 *
 */
@Service
public class SuppliersServiceImpl extends ServiceImpl<SuppliersMapper, Suppliers>
    implements SuppliersService{

    @Autowired
    SuppliersMapper suppliersMapper;

    @Override
    public Page<Suppliers> getPage(SupplierPageDto pageDto) {
        LambdaQueryWrapper<Suppliers> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.like(Suppliers::getName,pageDto.getName());
        lambdaQueryWrapper.like(Suppliers::getContactName,pageDto.getContactName());
        lambdaQueryWrapper.like(Suppliers::getAddress,pageDto.getAddress());
        return suppliersMapper.selectPage(new Page<Suppliers>(pageDto.getPageNow(), 4),lambdaQueryWrapper);
    }

    @Override
    public void addSupplier(Suppliers suppliers) {
        suppliers.setCreatedAt(new Date(System.currentTimeMillis()));
        suppliersMapper.insert(suppliers);
    }

    @Override
    public void updateSupplier(Suppliers suppliers) {
        suppliers.setUpdatedAt(new Date(System.currentTimeMillis()));
        suppliersMapper.updateById(suppliers);
    }
}




